<?php

/**
 * @author Pwint Phyu Shwe
* subscribe Controller
*
* Maps to the following url
* http://domain/index.php/subscribe
* or
* http://domain/index.php/subscribe/index
*/
class Subscribe extends CI_Controller {
  	function __construct() {
  		parent::__construct();
                  
  	}
    /**
     * This method is called when user click 'Newsletter' link 
     * from Footer Page
     * @return [type] [description]
     */
    function index(){
      $data['title'] = 'Maykha: Newsletter Subscription';
      $this->load->view('pages/subscribe', $data );
    }
    function send(){
        $data['title'] = 'Broadcast Message in Portal';
        $data['action'] = 'admin/message/broadcast';
        $this->load->view('admin/broadcast_view', $data);
    }
    function add(){
       $emailID = $_POST['emailID'];

       $status = array("STATUS"=>"false", "result"=>'Your subscription is unsuccessful. Please try again.');
       if(isset($emailID)){
            $subscription['emailID'] = $emailID;
            $subscription['is_active']= 1;
            $subscription['last_updated'] =  date('d-m-Y H:m:s');
            $this->load->model('Subscription_model','',TRUE);
            //check email pre exist
            if ($this->Subscription_model->check_email($emailID)){
                $status = array("STATUS"=>"false", 
                                "result"=>'This email is already registered. Plase contact admin@maykhaclassifieds.com for any technical problems'
                                );

            }else{
              $status = array("STATUS"=>"true", "result"=> 'Thank you for subscribing our newsletter. We will keep you update with useful news');
              $insertSubscription =  $this->Subscription_model->save($subscription);
            }
        }

       echo json_encode ($status) ;
    }
	
}
?>
